package io.terminus.sapp.contract.configs

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket

/**
 * swagger配置项
 * @author wangmeng
 * @date 2018/2/28
 */
@Configuration
class SwaggerConfig : WebMvcConfigurer {

    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/")

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/")
    }

    @Bean
    fun restApi(): Docket {
        return Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("io.terminus"))
                .paths(PathSelectors.any())
                .build()
    }

    fun apiInfo(): ApiInfo {
        return ApiInfoBuilder().contact(Contact("王猛", "http://git.terminus.io/sapp/contract-center", "wangmeng@terminus.io")).title("合同中心RESTAPI文挡").version("V1.0")
                .description("所有的接口请遵循restful规范").build()
    }
}